package cn.hhchat.wp.dto.msg;

import com.fasterxml.jackson.annotation.JsonIgnore;

import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;

/**
 * Created this one by HMH on 2017/7/2.
 */
public class RMsgModel implements Serializable {

    private Map<String, Object> data ;

    public RMsgModel() {
        data = new HashMap<>();
    }

    public RMsgModel add(String key, Object value) {
        data.put(key, value);
        return this;
    }

    public Integer getInt(String key) {
        return get(key, Integer.class);
    }

    public Long getLong(String key) {
        return get(key, Long.class);
    }

    public String getString(String key) {
        return get(key, String.class);
    }

    public <T> T get(String key, Class<T> cls) {
        Object o = data.get(key);
        if (o != null) {
            return cls.cast(o);
        }
        return null;
    }

    @JsonIgnore
    public Map<String, Object> data() {
        return this.data;
    }

}
